<template>
  <view>
    <!-- #ifdef APP-PLUS -->
    <view class="status_bar"></view>
    <!-- #endif -->
    <!-- #ifndef MP-WEIXIN -->
    <u-navbar title="门店导航" :background="background"> </u-navbar>
    <!-- #endif -->
    <view>
      <view class="shop">
        <view class="search">
          <u-search
            placeholder="搜索门店"
            v-model="searchVal"
            @custom="search"
            @search="search"
            bg-color="#FFFFFF"
          ></u-search>
        </view>
        <view v-if="list.length != 0">
          <view v-for="(item, index) in list" :key="index" @click="toStore(item)">
            <view class="shop-box">
              <!-- 商品主图 -->
              <view class="shop-box-img">
                <image
                  :src="
                    'https://copartner.oss-cn-beijing.aliyuncs.com/' +
                    (item.company_details.site_logo ||
                      'logo/2403/12/kLg9LUmAwobI2y6DtO0HqXp9dXI7GUDGpYlYTPh8.png')
                  "
                >
                </image>
              </view>
              <!-- 商品信息 -->
              <view class="shop-box-info">
                <text class="title one_ellipsis">{{
                  item.company_details.company_name || "测试"
                }}</text>
                <view class="tip">
                  <text class="tip-content one_ellipsis">{{
                    item.categorys || "暂无"
                  }}</text>
                  <text class="tip-sold"
                    >已售 {{ item.company_details.order_count || "0" }}</text
                  >
                </view>
                <view class="seg"></view>
                <view class="condition">
                  <view class="title time">
                    <text> 配送时间</text>
                    <text class="times"
                      >{{ item.company_details.open_time | timeFilter }}-{{
                        item.company_details.end_time | timeFilter
                      }}</text
                    >
                  </view>
                  <view class="title money"> 距离{{ item.distance }}km </view>
                </view>
                <view class="address">
                  <text class="address-info one_ellipsis"
                    >地址：{{
                      item.company_details.company_address || "暂无"
                    }}</text
                  >
                  <view
                    class="iphone"
                    @click.stop="call(item.company_details.site_phone)"
                  >
                    <image src="/static/image/iphone.png"></image>
                  </view>
                </view>
              </view>
            </view>
          </view>
        </view>
        <view class="noshop" v-else>
          <image src="../../static/image/sotre_nodata.png"></image>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { $https } from "@/static/js/request.js";
export default {
  data() {
    return {
      list: [],
      searchVal: "",
      background: { background: "#ffffff" },
      option: {},
    };
  },
  onLoad(option) {
    let { lng, lat } = JSON.parse(option.location);
    this.option = {
      lng,
      lat,
      page: 1,
      size: 100000,
      name: "",
    };
    this.getList(this.option);
  },
  filters: {
    timeFilter: function (value) {
      if (!value) return "暂无";
      return value.slice(0, 5);
    },
  },
  methods: {
    // 搜索
    search() {
      this.option.name = this.searchVal;
      this.getList(this.option);
    },
     // 去门店
    toStore(item) {
      // #ifdef MP-WEIXIN
      wx.navigateTo({
        url: "/subindex/webview/webview?url=" + item.domain_name,
      });
      // #endif
      // #ifndef MP-WEIXIN
      window.location.href = item.domain_name;
      // #endif
    },
    // 获取列表
    getList(data) {
      $https(
        "GET",
        "getStoreList",
        data,
        (res) => {
          if (res.data.errcode == 0) {
            this.list = res.data.data.list;
          } else {
            this.$u.toast(res.data.errmsg);
          }
        },
        true
      );
    },
  },
};
</script>

<style lang="scss">
/deep/.u-title {
  font-weight: 900 !important;
  color: black !important;
  font-size: 36rpx !important;
}
.search {
  width: 90%;
  margin: 20rpx auto;
}
.shop {
  width: 100%;
  position: relative;

  &-box {
    box-sizing: border-box;
    margin: 30rpx 30rpx 30rpx 30rpx;
    background-color: #ffffff;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 10rpx;
    border-radius: 10rpx;

    &-img {
      width: 180rpx;
      height: 180rpx;
      border-radius: 10rpx;
      padding: 20rpx;
      box-sizing: content-box;
      image {
        width: 100%;
        height: 100%;
      }
    }

    &-info {
      width: 430rpx;
      display: flex;
      flex-direction: column;
      justify-content: space-evenly;
      height: 192rpx;
      position: relative;

      .collect {
        position: absolute;
        bottom: 135rpx;
        right: -42rpx;
        width: 84rpx;
        height: 73rpx;
      }

      .title {
        width: 100%;
        font-size: 26rpx;
        font-weight: 600;
        color: #333;
      }

      .tip {
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;

        &-content {
          font-size: 20rpx;
          font-weight: 400;
          color: #656565;
          width: 300rpx;
        }

        &-sold {
          width: 130rpx;
          font-size: 19rpx;
          font-weight: 400;
          color: #656565;
          white-space: nowrap;
          text-align: right;
        }
      }

      .seg {
        width: 100%;
        height: 1rpx;
        background-color: #e5e5e5;
      }

      .condition {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;

        .title {
          font-size: 20rpx;
          font-weight: 400;
          color: #656565;
          white-space: nowrap;
        }

        .time {
          padding-left: 14rpx;
          background-color: #fff5e7;
          min-width: 210rpx;
          width: 224rpx;
          height: 30rpx;
          line-height: 30rpx;
          position: relative;

          text {
            position: relative;
            top: 0rpx;
          }
        }

        .times {
          color: #d75131;
          margin-left: 10rpx;
        }

        .money {
          width: 160rpx;
          text-align: right;
        }

        .moneys {
          color: #d75131;
          margin-right: 10rpx;
        }
      }

      .address {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;

        &-info {
          width: 380rpx;
          font-size: 20rpx;
          font-weight: 400;
          color: #656565;
        }

        .iphone {
          width: 23rpx;
          height: 23rpx;
          display: flex;
          justify-content: center;
          align-items: center;

          image {
            width: 80%;
            height: 80%;
          }
        }
      }
    }
  }
}
.noshop {
  width: 580rpx;
  height: 360rpx;
  margin: 65rpx auto 0;
  image {
    width: 100%;
    height: 100%;
  }
}
</style>
